#ifndef RECITEWORD_H
#define RECITEWORD_H

#include <QPlainTextEdit>
#include <QTextEdit>
#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
#include <QCheckBox>
#include <QStringList>

#define MAXNUM_OF_WORDS 1000
#define DEFAULT_DEGREE 100.0
#define REMEMBERED_DEGREE DEFAULT_DEGREE/10
//#define MIN_DEGREE (float)DEFAULT_DEGREE/100	//never less than this value
#define MIN_DEGREE (float)DEFAULT_DEGREE/10/5	//never less than this value
#define MAX_DEGREE (float)DEFAULT_DEGREE*100	//never larger than this value
#define GROUP_DEGREE DEFAULT_DEGREE*20		//20 one group if not remembered

#define TIMER_INTERVAL 1			//unit : minute

//default file for Eee Note

#define DEFAULT_DICT_FILE "/mnt/extsdcard/dict/dict1.xml"
#define DEFAULT_SPEECH_PATH "/mnt/extsdcard/voice"
#define CONFIG_FILE "/eTablet/etc/reciteword.conf"

//for test
/*
#define DEFAULT_DICT_FILE "./dict1.xml"
#define DEFAULT_SPEECH_PATH "/mnt/extsdcard/voice"
#define CONFIG_FILE "./reciteword.conf"
*/
#define DEFAULT_AUTO_SPEECH true
#define DEFAULT_SHOW_EXAMPLE false


typedef struct ConfigFile_st{
  QString dictfile;
  QString speechpath;
  bool autospeech;
  bool showexample;
} ConfigFile_st;

class ReciteWord : public QWidget
{
  Q_OBJECT
public:
  ReciteWord(QWidget *parent=0);
  ~ReciteWord();
  int initReciteWord();
  //  int initReciteWord(QString dictpath);
  //void readConfigFile();
  int readConfigFile();
  void getSettings();
  bool initOK();
  QStringList getPaths();
  void setPaths(QStringList paths);
  int record();

  //protected:
private slots:
  //  void showTrans();
  void know();
  void unKnow();
  void knowRight();
  void knowWrong();
  void nextWord();
  void speech();
  void showExampleEdit(bool checked);
  void setAutoSpeech(bool checked);
  void updateRememberTime();
  void test();

private:
  //QLineEdit *nameLine;
  //QTextEdit *addressText;
  //QAction *newAct;		//if not visited, no need defined here
  //QAction *openAct;

  QLabel *statisticLabel;
  QLineEdit *wordLine;
  QLabel *phoneticLabel;
  QTextEdit *transEdit;
  QTextEdit *exampleEdit;
  QCheckBox *autoSpeechBox, *showExampleBox;
  

  QPushButton *knowBtn, *unknowBtn, *rightBtn, *wrongBtn, *nextBtn;

  QString dictfile;
  int wordIndex;
  int rememberedCnt;

  bool initOKFlag;

  //store the words
  struct{
    struct {
      QString word, trans, phonetic, example;
      float degree;			//difficult degree of a word
      int time;				//time of remembered (in mins)
    } words[MAXNUM_OF_WORDS];
    unsigned int num;			//total num of words
  }dict;

  ConfigFile_st configFile, configFileBak; 
  int  getWordIndex();
  void clearAllText();
  void backupConfig();
  QWidget *mParent;
};

/*
class ReciteWordWidget : public QWidget
{
  Q_OBJECT
public:
  ReciteWordWidget(QWidget *parent=0);
};
*/

#endif
